#include "javaLang.h"
#include "baseLang.h"
JavaLanguage::JavaLanguage(const string& name) : CompileLanguage(name) {
    suffix = "java";
    extra_memory = 64 * 1024 * 1024;
    extra_time = 2000;
    suffixMap.emplace("java", "java");
}
std::string JavaLanguage::getBinaryFilename(std::string src) const {
    int x = src.rfind('.');
    if (x == -1) {
        return src + ".class";
    }
    return src.substr(0, x + 1) + "class";
}
std::string JavaLanguage::compileFileStr(std::string filename, std::string target) const {
    if (target == "") {
        target = getBinaryFilename(filename);
    }
    string command = "javac -encoding utf-8 -J-Xms32m -J-Xmx256m -classpath " + target + " " + filename;
    return command;
}
//  "-Xms32m", "-Xmx256m","-Djava.security.manager","-Djava.security.policy=./java.policy", "-Dfile.encoding=utf-8"
std::string JavaLanguage::runFileStr(std::string filename) const {
    int x = filename.rfind('/');
    string pre = "java -Xms32m -Xmx256m -Djava.security.manager -Dfile.encoding=utf-8 ";
    if(x == -1)
        return pre + filename;
    int dis = filename.rfind('.') - x - 1;
    string path = filename.substr(0, x + 1);
    return pre + " -cp " + path + " " + filename.substr(x + 1,dis);
}

const Language* JAVA8_LANG = new JavaLanguage{ "java" };

